package com.qf.iot.controller;


import com.qf.iot.core.vo.R;
import com.qf.iot.dto.PageDto;
import com.qf.iot.entity.QfDevice;
import com.qf.iot.entity.QfProduct;

import com.qf.iot.service.Impl.QfProductServiceImpl;

import com.qf.iot.vo.PageResult;
import com.qf.iot.vo.Result;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 作者：肖骏麟
 * 时间:2023/10/28 10:19
 * 描述：优化小子
 */
    @RestController
    @RequestMapping("product")
    @CrossOrigin
public class QfProductController {

    @Autowired
    private QfProductServiceImpl qfProductService;

    @PostMapping("page")
    public PageResult<QfProduct> page(@RequestBody PageDto<QfProduct> pageDto){

        return qfProductService.page(pageDto);
    }
    @PostMapping("save")
    public R save(@RequestBody QfProduct qfProduct){
        qfProductService.insert(qfProduct);
        return R.ok(0,"success");
    }
    @PostMapping("update")
    public R update(@RequestBody QfProduct qfProduct){
        qfProductService.updateById(qfProduct);
        return R.ok(0,"success");
    }
    @GetMapping("all")
    public List<QfProduct> findAll(){
        return qfProductService.list();
    }
    @PostMapping("delete/{id}")
    public R delete(@PathVariable String id){
        qfProductService.removeById(id);
        return R.ok(0,"success");
    }

}
